package com.chain.voter.record;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;

/**
 * Created by baoyunfeng on 2018/6/9.
 */

public class SharePreferenceUtil {

    public static final String library = "library";

    public static void setShareListModel(Context context,String key,ShareListModel shareListModel){
        SharedPreferences mSharedPreferences = context.getSharedPreferences(library, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putString(key,new Gson().toJson(shareListModel));
        editor.commit();
    }

    public static String getShareListModelJson(Context context,String key){
        SharedPreferences  sp = context.getSharedPreferences(library, Context.MODE_PRIVATE);
        String shareListModelJson = sp.getString(key,"");
        return shareListModelJson;
    }

    public static ShareListModel getShareListModel(Context context,String key){
        SharedPreferences  sp = context.getSharedPreferences(library, Context.MODE_PRIVATE);
        String shareListModelJson = sp.getString(key,"");
        return new Gson().fromJson(shareListModelJson,ShareListModel.class);
    }
}
